<?php
class InfoController extends Zend_Controller_Action
{
	// 初始化
	function init()
	{
		// 取得数据库指针
		$this->view->action=$this->_getParam('action');
		$this->view->controller=$this->_getParam('controller');
		$this->view->title = '软件教研室';
	}

	// 处理no action异常
	function __call($method, $args)
	{
		if ('Action'==substr($method, -6)) {
			$this->view->action=substr($method, 0, -6);
			$this->view->param=$this->_getAllParams();
			$this->renderScript('error/no-action.php');
		}
		else // 其他异常
			$this->_redirect('/');
	}

	/* 下面是action处理函数: ***************************/

	// 首页
	function indexAction()
	{
		$this->renderScript('error/on-doing.php');
	}

	// 教研室新闻
	function newsAction()
	{
		$this->view->title = '最新动态－软件教研室';
		$this->view->private = 0;
		$table = new info;
		$this->view->data = $table->fetch(false, 0); // public news
		$this->view->data = info::format($this->view->data);
	}

	// 内部通知
	function noticeAction()
	{
		$this->view->title = '内部通知－软件教研室';
		$this->view->private = 1;
		$table = new info;
		$this->view->data = $table->fetch(true, 0); // private notice
		$this->view->data = info::format($this->view->data);
		$this->renderScript('info/news.php');
	}

	// 增加新闻或内部通知的对话框
	function editnoticeAction()
	{
		// authority check
		if (!auth::check(auth::EDIT_LAB_STUFF)) {
			$this->view->msg='你的权限不够。';
			$this->renderScript('error/msg.php');
			return;
		}

		$this->view->private = $this->_getParam('private');
		$this->view->nid = intval($this->_getParam('NId'));
		$this->view->title = '软件教研室';
		if ($this->view->nid>0) {
			$table = new info;
			$result = $table->fetch(0, $this->view->nid);
			$this->view->data = $result[0];
			$this->view->private = $result[0]['Private']=='Y'?'1':'0';
		}

	}

	// 增加或更新新闻或内部消息
	function updateAction()
	{
		// authority check
		if (!auth::check(auth::EDIT_LAB_STUFF)) {
			$this->view->msg='你的权限不够。';
			$this->renderScript('error/msg.php');
			return;
		}

		$db = new info;
		$nid = $this->_getParam('NId');
		$param = $this->_getAllParams();
		$this->view->private = $param['Private'] = 
						$param['Private'] ? 'Y' : 'N';
		$param['Teacher'] = auth::name();
		$param['PostTime'] = time();
		if ($nid==0)
			$this->view->result = $db->add($param);
		else
			$this->view->result = $db->update($param);

	}

	// 显示新闻或内部通知
	function viewAction()
	{
		$this->view->title = '详细信息－软件教研室';
		$db = new info;
		$nid = $this->_getParam('NId');
		$result = $db->fetch(0, $nid);
		$result = info::format($result);
		$this->view->data = $result[0];
		$this->view->private = $result[0]['Private']=='Y'?'1':'0';
	}

	// 删除新闻或通知
	function delAction()
	{
		// authority check
		if (!auth::check(auth::EDIT_LAB_STUFF)) {
			$this->view->msg='你的权限不够。';
			$this->renderScript('error/msg.php');
			return;
		}

		$this->_helper->viewRenderer->setNoRender();
		$db = new info;
		$nid = $this->_getParam('NId');
		$result = $db->del($nid);
		echo "$result";
	}

	// 资料下载
	function resourceAction()
	{
		$this->view->title = '资料下载－软件教研室';
		$db = new course;
		$this->view->data = $db->courseware(0, 0);
	}

	// 教研室论文
	function papersAction()
	{
		$this->renderScript('error/on-doing.php');
	}

	// 教研室项目
	function projectsAction()
	{
		$this->renderScript('error/on-doing.php');
	}

	// 教研室奖励
	function awardsAction()
	{
		$this->renderScript('error/on-doing.php');
	}

	// 教研室著作
	function booksAction()
	{
		$this->renderScript('error/on-doing.php');
	}
	

};
?>
